import { Base } from '../base.js';

class Order extends Base {
	
	add(orderInfo) {
		var params = {
			url: 'v1/order/add',
			type: 'POST',
			data: {
				orderInfo:orderInfo
			}
		};
		return this.request(params);
	}
	
	
	/**
	 * 根据订单id获取订单详情
	 * @param {Object} id 订单id
	 */
	getDetail(id){
		var params = {
			url: 'v1/order/detail?id='+id
		}
		return	this.request(params);
	}
	
	/**
	 * 获取未支付的订单详情
	 * @param {Object} id
	 */
	getUnpaidDetail(id){
		var params = {
			url: 'v1/order/unpaid_detail?id='+id
		}
		return	this.request(params);
	}
	
	/**
	 * 获得所有订单,page 从第一页1开始
	 * @param {Object} status 订单状态
	 * @param {Object} page 该订单状态下第几页
	 */
	getList(status, page){
		var params = {
			url: 'v1/order/list?status=' + status + '&page=' + page
		}
		return	this.request(params);
	}
	
	
	getTodoCounts(){
		var params = {
			url: 'v1/order/todoCounts'
		}
		return	this.request(params);
	}
	
	
	receipt(id){
		var params = {
			url: 'v1/order/receipt',
			type: 'POST',
			data: {
				id:id
			}
		};
		return this.request(params);
	}
	
	
	/**
	 * 取消订单
	 */
	cancel(orderId, reason){
		var params = {
			url: 'v1/order/cancel',
			type: 'POST',
			data: {id: orderId, reason: reason}
		};
		return this.request(params);
	}
	
	
	/**
	 * 新增订单评论
	 */
	comment(commentInfo){
		var params = {
			url: 'v1/order/comment',
			type: 'POST',
			data: {commentInfo: commentInfo}
		};
		return this.request(params);
	}
	
	
	
	
	
	
	
	
	
	
	
	



	/*更新订单状态*/
	updateOrderStatus(id, order_status, callback) {
		var allParams = {
			url: 'order/update_status',
			type: 'POST',
			data: {id: id, order_status: order_status }
		};
		return this.request(allParams);
	}
	
	/**
	 * 取消订单
	 */
	createOrderReturnCancel(orderReturnInfo){
		var allParams = {
			url: 'order/return_cancel',
			type: 'POST',
			data: {orderReturnInfo: orderReturnInfo}
		};
		return this.request(allParams);
	}

	/**
	 * 退款或退款退货
	 */
	createOrderReturnMoneyAndGoods(orderReturnInfo){
		var allParams = {
			url: 'order/return_cancel_money_goods',
			type: 'POST',
			data: {orderReturnInfo: orderReturnInfo}
		};
		return this.request(allParams);
	}
	
};

export { Order };